<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>找回密码</title>
    <link rel="stylesheet" href="http://120.46.82.82:8080/code/static/layui/css/layui.css"/>
    <link rel="stylesheet" href="http://120.46.82.82:8080/code/static/fsLayui/plugins/jquery/jquery.min.js"/>

    <!--绝对路径：D:\Springboot_Java\code\src\main\resources\static\static\fsLayui\plugins\jquery\jquery.min.js-->
    <!--http://120.46.82.82:8080/code/+-->
    <!--static/static/layui/layui.js-->
    <!--${pageContent.request.ContentPath}-->
</head>
<body style="height: 300px">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px">
    <legend class="">找回密码</legend>
</fieldset>
<!--action="/code"-->
<form class="layui-form" action="/code" method="post" style="text-align: center">
    <div class="layui-form-item" style="margin-bottom: 5px">
        <label class="layui-form-label">&nbsp;&nbsp;邮&nbsp;&nbsp;箱：</label>
        <div class="layui-input-inline">
            <input type="email" lay-verify="email" id="email" name="email" required="true" placeholder="请输入注册时填写的邮箱地址"
                   autocomplete="off"
                   class="layui-input"
                   style="width: 280px"/>
        </div>
    </div>

    <div class="layui-form-item" style="margin-bottom: 5px">
        <label class="layui-form-label">验&nbsp;&nbsp;证&nbsp;&nbsp;码：</label>
        <div class="layui-input-inline" style="text-align: left">
            <input type="text" lay-verify="code" id="code" name="code" required="true" placeholder="请输入验证码"
                   class="layui-input"
                   style="width: 120px;
                   display: inline-block;
                    margin-right: 20px"
            />
            <button id="codeBtn" lay-submit="" lay-filter="sendEmail" class="layui-btn layui-btn-normal">获取验证码</button>
        </div>
    </div>

    <div class="layui-form-item" style="margin-top: 15px;text-align: center;">
        <button class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="submitForm"
                style="width: 120px">提交
        </button>
    </div>

</form>
<script type="text/javascript" src="http://120.46.82.82:8080/code/static/layui/layui.all.js"></script>
<script type="text/javascript" src="http://120.46.82.82:8080/code/static/js/jquery-1.8.3.min.js"></script>

<script type="text/javascript" src="http://120.46.82.82:8080/code/static/js/jquery.cookie.js"></script>
<script type="text/javascript">


    layui.use(['form', 'jquery'], function () {
        var $ = layui.$;
        var form = layui.form;
        //刷新界面 所有元素
        form.render();
        form.on('submit(sendEmail)', function (data) {
            var email = data.field.email;
            $('#codeBtn').attr({"disabled":"disabled"})
            layer.msg("请稍等！")
            var url = "http://120.46.82.82:8080/code/user/sendEmail"
            $.post(url,{email:email},function (result) {
                    if (result.success){
                        layer.msg("验证码已发送到你的邮箱，请注意查收，如果长时间没有收到邮箱，请联系管理员！",{
                            icon:1,
                            time:5000
                        },function () {
                            // 获取焦点
                            $("#code").focus();
                        });
                    }else{
                        layer.msg(result.errorInfo,{
                            icon:5,
                            time:5000
                        },function () {
                            // 获取焦点
                            $('#codeBtn').remove("disabled");
                        });
                    }
                },'json');

            return false;
        });


        /**
         * 提交监听
         */
        form.on('submit(submitForm)', function (data) {
            var code = $("#code").val();
            console.log(code);
            if (code == ''){
                layer.msg("请输入验证码");
                // 获取焦点
                $("#code").focus();
                return false;
            }
            var url = "http://120.46.82.82:8080/code/user/checkCode";
            $.post(url,{emailCode:code},function (result) {
                if (result.success){
                    layer.msg("已通过验证，密码已经重置为123123,请登录后立刻修改密码",{
                        icon:1,
                        time:5000
                    },function () {
                        // 刷新一下父页面
                        parent.window.location.reload()
                    });
                }else{
                    layer.msg(result.errorInfo,{
                        icon:5,
                        time:5000
                    });
                }
            },'json');
            return false;
        });
    });

</script>
</body>
</html>